package com.gcd.gym.api;


import com.gcd.gym.model.chart.CourseGrading;
import com.gcd.gym.model.chart.CourseHot;
import com.gcd.gym.service.ChartService;
import com.gcd.gym.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/v1/charts",produces = MediaType.APPLICATION_JSON_VALUE)
public class ChartsApi {
    private ChartService chartService;

    @Autowired
    public void setChartService(ChartService chartService) {
        this.chartService = chartService;
    }


//    查询热门课程
    @GetMapping("/courseHotChart")
    public ResponseEntity<JsonResult<?>> courseHotChart() {
        List<CourseHot> courseHots = chartService.courseHotChart();
        if(courseHots==null) {
            return ResponseEntity.ok(JsonResult.fail("没有热门课程！"));
        } else {
            return ResponseEntity.ok(JsonResult.success(courseHots));
        }
    }

//    课程评分统计
    @GetMapping("/courseGrading")
    public ResponseEntity<JsonResult<?>>  courseGrading() {
        List<CourseGrading> courseGradings=chartService.courseGrading();
        if(courseGradings==null) {
            return ResponseEntity.ok(JsonResult.fail("没有课程评分！"));
        } else {
            return ResponseEntity.ok(JsonResult.success(courseGradings));
        }
    }
}
